interface IloginViewModel extends ng.IScope{
    userName:string;
    passWord:string;
    loginEvent():void;
    seeks:any;
    form:any; 
}
interface ImainRootScope extends ng.IRootScopeService{
     islogin:any;
}
class loginController{
    intervalDes:any;
        /**
     * 野狗地址
     */
    // wilddogUrl: string;
    //用户id 以及 版本号
    // loginId:any;
    //版本号
    version:string;
    content:string;
    //更新内容
    contentUpdate:string;

    
    // versionTms="V18-0315"; //"V2.12.X-1222"

    constructor(private $scope:IloginViewModel,private loginService:ILoginService,private $rootScope:ImainRootScope,private $state:ng.ui.IStateService,private $timeout:ng.ITimeoutService,
        private $interval:ng.IIntervalService,private routeService: routeService){
        this.$scope.loginEvent = this.loginEvent;
        // /**登录背景 */
        this.$rootScope.islogin = true;
        
        //野狗
        // this.wilddogUrl = this.routeService.getWilddogUrl();   //"https://wd6091211065qhjgok.wilddogio.com/"; //

        this.$scope.seeks = false;   
        var toDo=()=> {
         }
        $timeout(toDo); 
        window.onload = function (){
            var input = document.getElementById("tmslogin_passWord");
            input.focus();
        }
        var random = Math.floor(Math.random()*10);
        $timeout(()=>{
            if(random >5){
                 $(".bglogin").addClass('bg2login')
            }else{
                $(".bglogin").addClass('bglogin');
            }
        })
    }
    loginEvent=()=>{
         this.$scope.seeks = true;
         //console.log(this.$scope.passWord);
        this.loginService.login(this.$scope.userName,this.$scope.passWord).then(res=>{
            // 头像 存储登录后拿到的头像信息，在个人信息中展示
            // console.log('res',res.data.headPath)
             this.$rootScope.islogin = false;
            //  this.$scope.seeks = true;                     
            let loginData = {
                id:res.data.id,
                realName:res.data.realName,
                userGroup:res.data.userGroup,
                userName:res.data.userName,
                commissionerType:res.data.commissionerType,
                jwtToken:res.data['jwtToken'],
                ExcelNum:0,
                excelTime:[]
            }
            window.localStorage.setItem("logToken",res.data.webRongToken); 
            // window.localStorage.setItem("logToken",res.data.rongToken);
            window.localStorage.setItem("loginData",JSON.stringify(loginData))
            window.localStorage.setItem('secAuthorizationTypeTag',res.data['secAuthorizationTypeTag'].join('+'));
            // bughd("user",{ name : res.data.userName, id : res.data.id});
            
            this.$rootScope.headPath=res.data.headPath||'../../src/img/a0.jpg';
            window.localStorage.setItem('headPath',this.$rootScope.headPath)
            
            

            // this.content = '1、在【运维】下增加子模块系统日志，且【系统权限管理】增加系统日志权限；2、工作报表导出增加工作报表：中粮东海结算明细表；3、应收结算列表页增加查询条件：实际发货起始时间、实际发货结束时间；'+
            //     '4、在【外接询价单】、【询价单新增】、【外接发货单】、【发货单新增】的所需车型选项中加入：拖车（集装箱）；在【发货单受理】、【发货单受理】-新增车辆、【车辆管理】、【运维】的车型选项中加入：拖车（集装箱）；'+
            //     '5、修改手机号码限制条件；6、新增消息类型：调度受理提醒。'
            // //获取版本号
            // this.loginService.getVersionInfo().then((res)=>{
            //     //已经添加一次版本号了，下次登录就不需要再添加了；当没有版本号时候，添加版本号
            //     if(res.data.version && res.data.version=="3"){
            //         this.version = res.data.version;
            //         this.contentUpdate = res.data.versionSummary;
            //     }else{
            //         //添加版本号
            //         this.loginService.addVersionInfo('1','3',this.content.toString()).then(res=>{
            //         })
            //         this.contentUpdate=this.content
            //     }
            //     window.localStorage.setItem('updateContent',this.contentUpdate)
                // this.$rootScope.$broadcast('showNewContentModal');
            //     // console.log('contentUpdate0',this.contentUpdate)
            // })
            
            this.$state.go("app.blank");

        },rej =>{
            this.$scope.seeks = false;
        })            
    }
}
angular.module("tms").controller("loginController",["$scope","loginService","$rootScope","$state","$timeout",'$interval','routeService',loginController]);